﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MM.Common.DBBase;

namespace MM.Common.Base
{
    public class LogHelper : LogService
    {
        // Fields
        public static readonly LogHelper Instance = new LogHelper();

        // Methods
        private LogHelper()
        {
            this.InitDbLog();
        }

        public LogHelper(string name): this(name, "")
        {
        }

        public LogHelper(LogSaveType saveType, string name): this(saveType, name, "")
        {
        }

        public LogHelper(string name, string objname): this(name, objname, "")
        {
        }

        public LogHelper(LogSaveType saveType, string name, string objname): this(saveType, name, objname, "")
        {
        }

        public LogHelper(string name, string objname, string evename)
        {
            this.InitDbLog(name, objname, evename);
        }

        public LogHelper(LogSaveType saveType, string name, string objname, string evename)
        {
            if (saveType == LogSaveType.LocalFile)
            {
                base.InitLog(name, objname, evename);
            }
            else if (saveType == LogSaveType.Database)
            {
                this.InitDbLog(name, objname, evename);
            }
        }

        private void InitDbLog()
        {
            base._log = new DbLogger();
        }

        private void InitDbLog(string logname)
        {
            this.InitDbLog(logname, "");
        }

        private void InitDbLog(string logname, string objectname)
        {
            this.InitDbLog(logname, objectname, "");
        }

        private void InitDbLog(string logname, string objectname, string eventname)
        {
            base._log = new DbLogger(logname, objectname, eventname);
            base._log.EnableLog = true;
            base._log.EnableExp = true;
        }
    }
}
